package com.hengshan.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hengshan.common.enums.ReturnCode;
import com.hengshan.domain.entity.BroLink;
import com.hengshan.exception.SystemException;
import com.hengshan.mapper.BroLinkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 友链表(BroLink)表服务实现类
 *
 * @author muxijun
 * @since 2023-12-07 16:14:40
 */
@Service("broLinkService")
public class BroLinkServiceImpl extends ServiceImpl<BroLinkMapper, BroLink> {

    @Autowired
    private BroLinkMapper broLinkMapper;

    @Transactional
    public boolean deleteByIds(List<Integer> ids) {
        return removeBatchByIds(ids);
    }

    @Transactional
    public boolean deleteById(Integer id) {
        return removeById(id);
    }

    public List<BroLink> getList() {
        return list();
    }

    public BroLink getOneById(Integer id) {
        return getById(id);
    }

    @Transactional
    public BroLink add(BroLink broLink) {
        boolean check = broLinkMapper.exists(new LambdaQueryWrapper<BroLink>().eq(BroLink::getName, broLink.getName()));
        if (check) {
            throw new SystemException(ReturnCode.CATEGORY_EXIST);
        }
        save(broLink);
        return getById(broLink.getId());
    }

    @Transactional
    public BroLink update(BroLink broLink) {
        updateById(broLink);
        return broLink;
    }
}

